package com.pkk.penguin.frame.know.shiro.shirodemo.singleversion;


import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

/**
 * Created by peikunkun on 2018/8/12 0012.
 */
public class ShiroDemo {

  public static void main(String[] args) {
    Factory<SecurityManager> securityManagerFactory = new IniSecurityManagerFactory("classpath:shiro.ini");
    SecurityManager securityManager = securityManagerFactory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);
    Subject subject = SecurityUtils.getSubject();
    UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken("root", "admin");
    try {
      subject.login(usernamePasswordToken);
      System.out.println("登录成功");
    } catch (AuthenticationException exception) {
      System.out.println("登录失败");
    }
  }



































  /*
   *//*第一步：读取配置文件，初始化SecurityManager工厂*//*
    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
    *//*实例化工厂*//*
    SecurityManager instance = factory.getInstance();
        *//*初始化操作，把SecurityManager绑定到其中进行初始化*//*
        SecurityUtils.setSecurityManager(instance);
    *//*当前当前执行的用户-就是获取主题*//*
    Subject subject = SecurityUtils.getSubject();*/
}
